package com.ruoyi.yuyuan.Utils;

import com.ruoyi.yuyuan.Mapper.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.ZoneOffset;

import static com.ruoyi.yuyuan.Utils.IdGenerator.BEGIN_TIMESTAMP;
import static com.ruoyi.yuyuan.Utils.IdGenerator.BIT_COUNT;

/**
 * @Author: kestrel
 * @Version:1.0
 * @Date: 2024/6/13
 */
@Component
public class MyUtils {
    /**
     * 处理分页查询中起始id为0的问题
     * @param startId 起始id
     * @return 处理后的startId变量
     */
    @Autowired
    private AgreementBlogMapper agreementBlogMapper;

    @Autowired
    private DealBlogMapper dealBlogMapper;

    @Autowired
    private PracticeBlogMapper practiceBlogMapper;

    @Autowired
    private DailyBlogMapper dailyBlogMapper;

    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private NoticeMapper noticeMapper;

    public long zeroHandler(Long startId, Long blogType, String type) {
        if (startId != 0) return startId;
        switch (type) {
            case "BlogAgreement":
                startId = agreementBlogMapper.getMaxStartId(blogType) + 1;
                break;
            case "BlogDeal":
                startId = dealBlogMapper.getMaxStartId() + 1;
                break;
            case "BlogPractice":
                startId = practiceBlogMapper.getMaxStartId() + 1;
                break;
            case "BlogDaily":
                startId = dailyBlogMapper.getMaxStartId() + 1;
                break;
            case "Comment":
                // 查找blogId对应的评论的最大id
                if(commentMapper.getMaxStartId(blogType)!= null){
                    startId = commentMapper.getMaxStartId(blogType) + 1;
                } else {
                    startId = 0L;
                }
                break;
            case "Notice":
                // 这里blogType是userId
                startId = noticeMapper.getMaxStartId(blogType) + 1;
                break;
        }
        System.out.println(startId);
        return startId;
    }
}
